﻿function displayTitle() {
	clearInterval(_global.setTxt);
	// 创建标题栏，坐标（4, 75） 990 * 20
	this.createTextField("txtTitle", this.getNextHighestDepth(), 4, 75, 990, 20);

	// 创建透明的MC，用来侦听鼠标事件，控制文字的滚动,深度尽可能的大，至少要比弹出窗口的值大
	_root.attachMovie("videoBar", "ctrlTitle", 1148555, {_x: 4, _y: 75, _width: 990, _height:20, _alpha: 0});

	txtTitle.wordWrap = false;
	txtTitle.html = true;
	txtTitle.autoSize = true;

	// 填充一串空白字符串，用于文字的滚动
	var tmp:String = "";
	for (var i:Number = 0; i < 340; i++) {
		tmp += "&nbsp;";
	}

	txtTitle.htmlText = "<b>" + currentInfo.data.meetingName + "</b>(" + currentInfo.data.meetingMode + ")    " + currentInfo.data.meetingTheme;

	var txtFlag:Boolean = true;
	var setTxt;
	
	trace(txtTitle._width);
	if (txtTitle._width > 990) {
		txtTitle.htmlText = txtTitle.text + tmp;
		txtTitle._width = 990;
		txtTitle.autoSize = false;
		
		// 创建提示框，用来显示会议标题
		this.createTextField("showAllContent", this.getNextHighestDepth(), -8000, -8000, 300, 100);
		showAllContent.border = 1;
		showAllContent.background = true;
		showAllContent.backgroundColor = 0xFF9900;
		showAllContent.multiline = true;
		showAllContent.wordWrap = true;
		showAllContent._width = 300;
		showAllContent.textWidth = 300;
		showAllContent._alpha = 30;
		showAllContent.swapDepths(ctrlTitle);
		showAllContent.html = true;
		showAllContent.htmlText = "<p align='center'><h1><b>" + currentInfo.data.meetingName + "</b></h1></p><p>" +
									currentInfo.data.meetingTheme + "</p>";
	
		// 添加单击事件
		ctrlTitle.onPress = function() {
			if (txtFlag) {
				clearInterval(_global.setTxt);
				txtFlag = false;
			} else {
				_global.setTxt = setInterval(scrollTxt, 50);
				txtFlag = true;
			}
		};
	
		ctrlTitle.onRollOver = function() {
			// 确定提示框的X/Y轴坐标
			var tmpX;
			if (_xmouse > 700) {
				tmpX = 700;
			} else {
				tmpX = _xmouse;
			}

			showAllContent._x = tmpX;
			showAllContent._y = _ymouse;
		};
	
		ctrlTitle.onRollOut = function() {
			showAllContent._x = -8000;
			showAllContent._y = -8000;
		};
	
		_global.setTxt = setInterval(scrollTxt, 50);
	} else {
		txtTitle.htmlText = txtTitle.text;
	}
}

function scrollTxt() {
	if (txtTitle.hscroll == txtTitle.maxhscroll) {
		txtTitle.hscroll = 0;
		txtTitle.htmlText = tmp + txtTitle.htmlText;
	}
	txtTitle.hscroll += 2;
}


// 初始化公告板
function initCallboard() {
	call_board.editable = false;
	call_board.html = true;
	styles = new TextField.StyleSheet();
	styles.setStyle("h1", {fontSize:'16px',color:'#FF0000',textAlign:'center'});
	call_board.styleSheet = styles;
	
	// 调整聊天显示区域的垂直滚动条
	updateVPosition();
	currentText.setFocus();
}


/**
 * @des 发送聊天内容
 * @param flag 类型，0为回车提交，1为按钮提交
 * @param cc 要发送的聊天内容
 */
function sendMsg(flag, cc) {
	var len:Number = 0;
	var newClientMsg:String;
	var newServerMsg:String;
	var tmpArr:Array;
	
	/**
	 * @des 变量len即为要判断的指定长度。如果是回车提交，则长度应该大于一，按钮提交则长度应该大于零
	 */
	if (flag == 1) {
		cc += "\n";
	}
	
	if (cc.length > 1) {
		/**
		 * @des 判断聊天对象
		 *      文本显示颜色：
		 *            服务器消息（红色#FF0000）
		 *            自己公共发言（绿色#008000）
		 *            自己私聊发言（黑色#000000）
		 *            其他人公共发言（蓝色#0000FF）
		 *            其他人发给自己的私聊信息（橘红色#FF9900）
		 */
		if (cbMemberListOfChat.selectedItem.data == "") {
			newClientMsg = "<b>" + memberName + "</b>说：<font color=\"#008000\"> " + cc + "</font>";
			newServerMsg = "<b>" + memberName + "</b>说：<font color=\"#0000FF\"> " + cc + "</font>";
		} else {
			newClientMsg = "<b>" + memberName + "</b>对<b>" + cbMemberListOfChat.selectedItem.data + "</b>说：<font color=\"#000000\"> " + 
							cc + "</font>";
			newServerMsg = "<b>" + memberName + "</b>对<b>" + cbMemberListOfChat.selectedItem.data + "</b>说：<font color=\"#FF9900\"> " + 
							cc + "</font>";
		}
		//tmpArr = newClientMsg.split(Key.ENTER);
		//newClientMsg = tmpArr.join('') + '<br>';
		//tmpArr = newServerMsg.split(Key.ENTER);
		//newServerMsg = tmpArr.join('') + '<br>';
		
		call_board.text += newClientMsg;
		
		// 将消息传至服务器
		nc.call("sendMsg",
				null,
				memberId,
				cbMemberListOfChat.selectedItem.data,
				currentInfo.data.meetingId,
				newServerMsg);
		
		// 调整聊天显示区域的垂直滚动条
		updateVPosition();
	}
	
	currentText.text = "";
}

// 聊天输入框的事件
var o:Object = new Object();
o.change = function(evt: Object) {
	var c = currentText.text;
	
	if (c.indexOf('\r') != -1) {
		sendMsg(0, c);
	}
}
currentText.addEventListener('change', o);
/**
按下回车键时发送消息
currentText.change = function(eventObj) {
	if (Key.getCode() == Key.ENTER) {
		sendMsg(0);
	}
}
*/

// 发送按钮的onRelease事件
btnSend.onRelease = function() {
	sendMsg(1, currentText.text);
};

/**
 * @des 初始化聊天控制信息
 */
function initChatCtrl() {
	var so:SharedObject = SharedObject.getRemote("meetingList", nc.uri, true);
	so.connect(nc);
	
	// 同步服务器端的私聊控制的设置
	so.onSync = function() {
		for (var i in so.data) {
			if (so.data[i].id == currentInfo.data.meetingId) {
				currentInfo.data.allowPrivateChat = so.data[i].allowPrivateChat;
				currentInfo.data.showAll = so.data[i].showAll;
			}
		}
	};
}

// 初始化聊天控制信息
initChatCtrl();

// 初始化公告板
initCallboard();